package xyz.labmem.lipx.core.tool

import com.alibaba.fastjson2.JSON
import com.alibaba.fastjson2.JSONObject
import org.smartboot.http.client.HttpClient
import java.util.concurrent.TimeUnit

object ReqTool {

    private val client = HttpClient("lipx.labmem.xyz", 80)

    fun checkUpdate(success: (JSONObject) -> Unit) {
        val res = client.get("/api/v1/version/getNew/CONSOLE")
            .done().get(5, TimeUnit.SECONDS)
        if (res.status == 200)
            success(JSON.parseObject(res.body()).getJSONObject("data"))
    }
    
    fun getDownLoadUrl(version: String, type: String): String =
        "https://gitee.com/labmem000/lipx-console-open/releases/download/v${version}/lipx-${type}"

}